<template>
    <div class="content">
        <div class="content-block ">
            <div class="list-block">
                <ul>
                    <li class="item-content item-link" v-on:click="choose">
                        <div class="item-media">
                            <i class="icon icon-underline"> </i>
                        </div>
                        <div class="item-inner">
                            <div class="item-title label">
                                单位选择
                            </div>
                            <div class="item-input">
                                <span id="unit"> </span>
                                <input type="text" value="{{unit}}"/>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media">
                                <i class="icon icon-leaf"> </i>
                            </div>
                            <div class="item-inner">
                                <div class="item-title label">
                                    数据类型
                                </div>
                                <div class="item-input">
                                    <select v-model="dateType" @change="dateTypeChange">
                                        <option>日数据</option>
                                        <option>月数据</option>
                                        <option>季度数据</option>
                                        <option>半年数据</option>
                                        <option>年数据</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </li>
                    <!-- Date -->
                    <li>
                        <div class="item-content">
                            <div class="item-media">
                                <i class="icon icon-calendar"> </i>
                            </div>
                            <div class="item-inner">
                                <div class="item-title label">
                                    时间
                                </div>
                                <input :type="timeType" v-model="time"/>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="content-block">
                <div class="row">
                    <div class="col-100">
                        <a @click="check" class="button button-big button-fill">查询</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import* as FStorage from '../util/FStorage'
    import {defaultDate} from '../common-config'

    export default {
        data(){
            return {
                unitStorageName: 'homeUnit',
                dateType: '日数据',
                timeType: 'date',
                time: defaultDate
            }
        },
        methods: {
            choose: function () {
                this.$router.go({name: 'unitChoose', params: {storageName: this.unitStorageName, needRoot: true}});
            },
            check: function () {
                var unit = FStorage.getLocalItem(this.unitStorageName);
                var params = {
                    type: this.timeType,
                    date: this.time.split('-').join(''),
                    depth: unit.layer - 1,
                }
                switch (unit.layer) {
                    case 2:
                        params['adminUnit2'] = unit.value
                        break;
                    case 3:
                        params['adminUnit2'] = unit.supper
                        params['adminUnit3'] = unit.value
                        break;
                }
                this.$router.go({name: 'homeResult', params: params});
            },
            dateTypeChange(){
                switch (this.dateType) {
                    case '日数据':
                        this.timeType = 'date';
                        this.time = '2016-06-22'
                        break;
                    case '月数据':
                        this.timeType = 'month';
                        this.time = '2016-06'
                        break;
                    default:
                        this.timeType = 'text';
                        this.time = 'wait for this type'
                }
            }
        },

        computed: {
            unit: function () {
                var value = FStorage.getLocalItem(this.unitStorageName).value;
                return value;
            }
        }
    }
</script>
<style>
</style>